#include "../head.h"


int main(int argc, char *argv[])
{
    // 获取指定网卡的各种基本信息
    int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
    struct ifreq ifr;
    strcpy(ifr.ifr_ifrn.ifrn_name, "ens33");
    
    ioctl(sockfd, SIOCGIFADDR, &ifr);
    printf("IP: %s\n", inet_ntoa(((struct sockaddr_in *)&(ifr.ifr_ifru.ifru_addr))->sin_addr));

    ioctl(sockfd, SIOCGIFBRDADDR, &ifr);
    printf("广播地址: %s\n", inet_ntoa(((struct sockaddr_in *)&(ifr.ifr_ifru.ifru_broadaddr))->sin_addr));

    ioctl(sockfd, SIOCGIFNETMASK, &ifr);
    printf("子网掩码: %s\n", inet_ntoa(((struct sockaddr_in *)&(ifr.ifr_ifru.ifru_netmask))->sin_addr));

    return 0;
}